<?php //pr ($this->getVars()) ?>
<fieldset id="messages">
<legend>
	<?php
		$incoming	= 'Принятые сообщения';
		$outcoming	= 'Отправленные сообщения';
	?>
	<?php if (isset($replieds)): ?>
		<?php $tofrom = 'To' ?>
	<b>	<?php echo $outcoming ?> </b> / <a href="/messages"><?php echo $incoming ?></a>
	<?php else: ?>
		<?php $tofrom = 'From' ?>
	<b>	<?php echo $incoming ?> </b>  / <a href="/messages/replieds"><?php echo $outcoming ?></a>
	<?php endif ?>
</legend>

<?php if (!empty($messages)): ?>
<?php //pr ($messages) ?>
<?php foreach ($messages as $k => $v): ?>
<ul>
	<?php //pr ($v) ?>
	<?php //pr ($lemur) ?>

<?php
	$login = $v[$tofrom]['login'];

	if (isset($v[$tofrom]['Foto'][0]['hash'])) {
		$foto = $v[$tofrom]['Foto'][0];
		$hash = $v[$tofrom]['Foto'][0]['hash'];
		$avatar = '<img src="/photos/' . $login . '/'. $hash .'_235.' . $foto['ext'] . '" title="'. $login .'"/>';
	} else {
		$avatar = $lemur->noFoto($v['To']['Profile']['sex']);
	}
?>
<li>    <a href="/user/<?php echo $login ?>"><?php echo $avatar ?></a> </li>

<li class="text">
	<?php echo $v['Message']['text'] ?><br /><br />

	<?php echo $time->timeAgoInWords($v['Message']['created']) ?>
</li>
<li>
<?php if (!isset($reply) && (!isset($replieds))): ?>
	<a href="/messages/read/<?php echo $v['Message']['id'] ?>"><?php echo __('read', true) ?></a><br />
<?php endif ?>
	<a href="/messages/delete/<?php echo $v['Message']['id'] ?>"><?php echo __('delete', true) ?></a>
</li>

<?php if (isset($reply)): ?>
<li>
	<?php echo $form->create('Message', array('url'=>$this->here)) ?>
	<?php echo $form->textarea('text') ?>
	<?php echo $form->end(__('reply', true)) ?>
</li>
<?php endif ?>

</ul>
<?php endforeach ?>
<?php else: ?>
	<ul>
	<li> Сообшений нет =/ </li>
	</ul>
<?php endif ?>
</fieldset>
